<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/17
 * Time: 22:26
 */

namespace frontend\widgets;


use common\models\c2\entity\ActivityPlayerModel;
use common\models\c2\search\ActivityPlayerSearch;
use common\models\c2\statics\ActivityPlayerState;
use yii\base\Widget;

class PlayerList extends Widget
{
    public $activity;
    public $pageSize = 20;

    public function run()
    {

        // $model = ActivityPlayerModel::find()->where(['activity_id' => $this->activity->id])
        //     ->andFilterWhere(['state' => ActivityPlayerState::STATE_CHECKED])
        //     ->orderBy(['total_vote_number' => SORT_DESC])->limit(4)->all();

        $searchModel = new ActivityPlayerSearch();
        $params = [
            'ActivityPlayerSearch' => [
                'activity_id' => $this->activity->id
            ],
            'pageSize' => $this->pageSize,
            // 'player-page' => $this->pageSize,
        ];
        $dataProvider = $searchModel->search($params);

        // sort
        $sort = $dataProvider->getSort();
        $sort->defaultOrder = ['total_vote_number' => SORT_DESC];
        $dataProvider->setSort($sort);

        return $this->render('playerListTop4', [
            'dataProvider' => $dataProvider
        ]);

    }
}